#include <stdio.h>

const int MAX_VALUE = 5000;
int counts[MAX_VALUE+1];

const int MAX_CNT = 100000;
int res[MAX_CNT+1];

int main() {
    for (int i = 0; i <= MAX_VALUE; ++i)
        counts[i] = 0;

    int N = 0;
    scanf("%d", &N);
    for (int i = 0; i < N; ++i) {
        int tmp = 0;
        scanf("%d", &tmp);
        ++counts[tmp];
    }

    for (int i = 1, cur_pos = 1; i <= MAX_VALUE; ++i)
        while(counts[i] > 0) {
            res[cur_pos++] = i;
            --counts[i];
        }

    char str[5];
    scanf("%s", str);

    int K = 0;
    scanf("%d", &K);
    for (int i = 0; i < K; ++i) {
        int tmp = 0;
        scanf("%d", &tmp);
        printf("%d\n", res[tmp]);
    }

    return 0;
}
